package com.mew.chess.core.game.yxx.game.message;

import com.zebra.common.ZebraBaseMessage;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.HashMap;


@Data
@ToString
@NoArgsConstructor
public class YxxPaymentMessage extends ZebraBaseMessage<YxxPaymentMessage> {

    private HashMap<Integer,Long> paymentMap = new HashMap<>(); //negative lose; positive win

    @Override
    public void write(ByteBuf b) {

        writeMsg(b);
    }

    public void writeMsg(ByteBuf b) {

        writeInt(b, paymentMap.size());
        for (Integer type : paymentMap.keySet()) {
            writeLongArray(b,new long[]{type,paymentMap.get(type)});
        }
    }


    @Override
    public YxxPaymentMessage read(ByteBuf b) {
        return null;
    }

    public void buildData(int type,long gold){
        Long oldGold = paymentMap.get(type);
        if (null==oldGold){
            paymentMap.put(type,gold);
        }else {
            paymentMap.put(type,gold+oldGold);
        }
    }

    public void clearInfo(){
        paymentMap.clear();
    }


}
